#ifndef DVPIECHART_H
#define DVPIECHART_H

#include <QWidget>
#include <QMap>
#include "dvDatabaseController.h"
#include "dvDatabaseControllerUsable.h"

class Nightcharts;

class dvPiePiece
{
public:
    explicit dvPiePiece(){m_name = "Unnamed"; m_color = QColor(Qt::red);
                          m_value = 100.0f; m_attached = true;}
    void setName(QString name) {m_name = name; }
    QString name(){ return m_name; }
    void setColor(QColor color) { m_color = color; }
    QColor color(){ return m_color; }
    void setValue(float value) { m_value = value; }
    float value(){ return m_value; }
    void setAttached(bool state) { m_attached = state; }
    bool attached(){ return m_attached; }

private:
    QString m_name;
    QColor m_color;
    float m_value;
    bool m_attached;
};

class dvPieChart : public QWidget, public dvDatabaseControllerUsable
{
    Q_OBJECT
public:
    explicit dvPieChart(QWidget *parent = 0);
    ~dvPieChart();

    void clear();
    void insertPiece(int region, double value, QColor &color, bool attached = true);
    void removePiece(int region);
    int  countPieces();
    void rebuildPieChart();
    void showPiece(int region, bool show);
    void setHiddenAllPiece(bool hidden);

    void set3dPie(bool on);
    void showLegend(bool show);
    void setRoundedLegend(bool on);

    void setTitle(const QString& title){ m_title = title; }

    void exportImageFile(const QString& fname);

protected:
    void paintEvent(QPaintEvent *e);
    void resizeEvent(QResizeEvent *e);

private:
    Nightcharts* m_pChart;
    QMap<int, dvPiePiece*> m_pieces;
    bool m_legendShow;
    QString m_title;
    
signals:
    
public slots:
    
};

#endif // DVPIECHART_H
